package com.dingding.webservice.ordercomment.impl;

import java.util.Date;

import com.dingding.bean.databean.request.ReqEvaluateDriver;
import com.dingding.bean.databean.response.DataResponse;
import com.dingding.common.core.beans.OrderComment;
import com.dingding.common.core.beans.special.SpecialOrderComment;
import com.dingding.common.core.config.SystemCode;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.service.BaseService;
import com.dingding.webservice.ordercomment.IOrderCommentService;

/**
 * @ClassName: OrderCommentServiceImpl
 * @Description: 订单评论Service实现类
 * @author YHQ
 * @date 2016年5月12日 下午3:27:57
 */
public class OrderCommentServiceImpl extends BaseService implements IOrderCommentService {

	
	@SuppressWarnings("unused")
	@Override
	/*public void addOrderComment(ReqEvaluateDriver reqEvaluateDriver, DataResponse dataResponse) {

		// 判断客户端传入参数是否为空
		if (reqEvaluateDriver == null || ToolUtil.isBlank(reqEvaluateDriver.getOrderId())
				|| reqEvaluateDriver.getStarLevel() == null) {
			setStatus(dataResponse, SystemCode.DATA_NULL_ERROR);
			return;
		}

		OrderComment orderComment = new OrderComment();

		orderComment.setOcId(ToolUtil.getUid());// 订单评论Id
		orderComment.setOrderId(reqEvaluateDriver.getOrderId());// 订单号
		orderComment.setEvaluateLevel(reqEvaluateDriver.getStarLevel());// 订单星级评分
		orderComment.setEvaluateLabel(reqEvaluateDriver.getStarLabel());// 评论标签
		orderComment.setEvaluateContent(reqEvaluateDriver.getStarContent());// 评论内容
		orderComment.setEvaluateDate(new Date());// 评论时间
		orderComment.setIsDispay(2);// 是否显示评论 1:显示 2:不显示

		// 添加评论(true:成功 false:失败)
		boolean add_commentstatus = super.orderCommentFacade.addOrderCommentInfo(orderComment);
		// 评价完成后,设置订单为已评价
		boolean order_commentstatus = super.userOrderTDao.setOrderAlreadyEvaluated(reqEvaluateDriver.getOrderId());
		// 获取车主ID
		String driverId = super.userOrderDao.getDriverId(reqEvaluateDriver.getOrderId());
		if (ToolUtil.isNotBlank(driverId)) {
			// 更新车主信誉等级
			super.userDetailDao.updateUserReputateLevel(driverId);
		}
		// 判断是否评论成功
		if (add_commentstatus && order_commentstatus) {
			setStatus(dataResponse, SystemCode.SUCCESS);
		} else {
			setStatus(dataResponse, SystemCode.ERROR);
		}

	}*/
	
	/**
	 * @Title: addOrderComment
	 * @Description: 添加订单评论信息
	 * @param reqEvaluateDriver
	 *            乘客评论内容
	 * @param dataResponse
	 *            响应客户端请求Bean
	 * @author YHQ
	 * @return void 返回类型
	 * 修改人：SUNZHICHENG
	 * 修改日期：2016-8-31
	 */
	
	public void addOrderComment(ReqEvaluateDriver reqEvaluateDriver, DataResponse dataResponse) {

		// 判断客户端传入参数是否为空
		if (reqEvaluateDriver == null || ToolUtil.isBlank(reqEvaluateDriver.getOrderId())
				|| reqEvaluateDriver.getStarLevel() == null) {
			setStatus(dataResponse, SystemCode.DATA_NULL_ERROR);
			return;
		}
		
		boolean add_commentstatus=false; // 添加评论(true:成功 false:失败)
		boolean order_commentstatus=false;// 评价完成后,设置订单为已评价
		boolean update_userLevel=false; //修改用户信誉等级
		//判断专车评价或普通评价， 评价类型 1：普通 2.出租车 3：专车	
		//如果评价类型 为3，则为专车订单评价
		 if (reqEvaluateDriver.getEvaluateType().equals(3) || reqEvaluateDriver.getEvaluateType().equals(4)) {
			
			SpecialOrderComment specialOrderComment=new SpecialOrderComment();
			
			specialOrderComment.setSpcId(ToolUtil.getUid());  // 订单评论Id
			specialOrderComment.setSpecialOrderId(reqEvaluateDriver.getOrderId()); // 订单号
			specialOrderComment.setEvaluateLevel(reqEvaluateDriver.getStarLevel());// 订单星级评分
			specialOrderComment.setEvaluateLabel(reqEvaluateDriver.getStarLabel());// 评论标签
			specialOrderComment.setEvaluateContent(reqEvaluateDriver.getStarContent());// 评论内容
			specialOrderComment.setEvaluateDate(new Date());// 评论时间
			specialOrderComment.setIsDispay(2);
			
			// 添加评论(true:成功 false:失败)
			add_commentstatus=super.orderCommentFacade.addSpecialOrderComment(specialOrderComment);
			// 评价完成后,设置订单为已评价
			order_commentstatus = super.iSpecialOrderCommentDao.setOrderAlreadyEvaluated(reqEvaluateDriver.getOrderId());
			// 获取专车车主ID
			String specialOwnerId=super.iSpecialOrderCommentDao.getSpecialOwnerId(reqEvaluateDriver.getOrderId());
			// 更新车主信誉等级
			update_userLevel=super.userSpecialOrderDao.updateUserReputateLevel(specialOwnerId);
			
		}else{	//出租车和普通评价

			
			OrderComment orderComment = new OrderComment();

			orderComment.setOcId(ToolUtil.getUid());// 订单评论Id
			orderComment.setOrderId(reqEvaluateDriver.getOrderId());// 订单号
			orderComment.setEvaluateLevel(reqEvaluateDriver.getStarLevel());// 订单星级评分
			orderComment.setEvaluateLabel(reqEvaluateDriver.getStarLabel());// 评论标签
			orderComment.setEvaluateContent(reqEvaluateDriver.getStarContent());// 评论内容
			orderComment.setEvaluateDate(new Date());// 评论时间
			orderComment.setIsDispay(2);// 是否显示评论 1:显示 2:不显示

			// 添加评论(true:成功 false:失败)
			add_commentstatus = super.orderCommentFacade.addOrderCommentInfo(orderComment);
			// 评价完成后,设置订单为已评价
			 order_commentstatus = super.userOrderTDao.setOrderAlreadyEvaluated(reqEvaluateDriver.getOrderId());
			// 获取车主ID
			String driverId = super.userOrderDao.getDriverId(reqEvaluateDriver.getOrderId());
			if (ToolUtil.isNotBlank(driverId)) {
				// 更新车主信誉等级
				update_userLevel=super.userDetailDao.updateUserReputateLevel(driverId);
			}
		
		}
	
			// 判断是否评论成功
			if (add_commentstatus && order_commentstatus) {
				setStatus(dataResponse, SystemCode.SUCCESS);
			} else {
				setStatus(dataResponse, SystemCode.ERROR);
			}

	}
	
	
	
	
	@Override
	public void setStatus(DataResponse dataResponse, int status) {

		String message = null;
		switch (status) {
		case SystemCode.SUCCESS:
			message = SystemCode.SUCCESS_MESSAGE;
			break;
		case SystemCode.ERROR:
			message = SystemCode.ERROR_MESSAGE;
			break;
		case SystemCode.USER_INFO_NOT_EXIST_ERROR: // 用户信息不存在
			message = SystemCode.USER_INFO_NOT_EXIST_MESSAGE;
			break;
		case SystemCode.CANCEL_ORDER_TOO_MUCH: // 取消次数超过三次
			message = SystemCode.CANCEL_ORDER_MUCH_MESSAGE;
			break;
		case SystemCode.PUBLISH_ORDER_TOO_MUCH: // 接单次数超过三次
			message = SystemCode.PUBLISH_ORDER_TOO_MUCH_MESSAGE;
			break;
		case SystemCode.DATA_NULL_ERROR: // 请求数据为空
			message = SystemCode.DATA_NULL_MESSAGE;
			break;
		case SystemCode.COUPON_ACTIVATION_FAIL:
			message = SystemCode.COUPON_ACTIVATION_FAIL_MESSAGE;// 优惠券激活失败
			break;
		case SystemCode.STORE_LOAG_NULL:
			message = SystemCode.STORE_LOAD_NULL_MESSAGE;// 使用优惠券失败
			break;
		default:
			break;
		}
		dataResponse.setResponseCode(status);
		dataResponse.setResponseMessage(message);

	}

}
